home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tlxtime6.zip / TIMESET.SLT < prev   
Text File  |  1991-10-03  |  13KB  |  423 lines

  1.  
  2. main()
  3. {
  4.     int count,hi_hour,lo_hour,hi_min,lo_min,hi_sec,lo_sec,local_hr,t;
  5.     int error, err_test, y1, y2, y3, y4, y5, day, month, year, timezone;
  6.     int julian1, julian2, julian3, julian4, julian5, julian6, julian7, julian8;
  7.     str utc_hour[3],slocal_hr[3],set_dos_time[20]="time ",set_dos_date[20]="date ";
  8.     str juldatestr[10] = " ";
  9.     str geordatestr[10] = " ";
  10.     str monthstr[3], daystr[3], yearstr[4];
  11.     str startdtmo[3], startdtdy[3], stopdtmo[3], stopdtdy[3];
  12.     int integerdate;
  13.  
  14. //************ TIME ZONE REFERENCE INFOMATION *********************************
  15.  
  16. //  ZONE   +13      GMT+13  +13
  17. //  ZONE   +13A   Mos+10  +13     MosS+10 +14    90/03/25:2   90/09/30:2
  18. //  ZONE   +1275  Chat.   +12.75 ChatS     +13.75 89/10/07:14  90/03/17:14
  19. //  ZONE   +12      GMT+12  +12
  20. //  ZONE   +12A   Mos+9   +12     MosS+9  +13    90/03/25:2   90/09/30:2
  21. //  ZONE   +12B   NZ      +12     NZ-S     +13    89/10/07:14  90/03/17:14
  22. //  ZONE   +11.5  Norf.I  +11.5
  23. //  ZONE   +11      GMT+11  +11
  24. //  ZONE   +11A   Mos+8   +10     MosS+8  +12    90/03/25:2   90/09/30:2
  25. //  ZONE   +11B   Vanu.   +11     VanuS     +12    89/09/23:14  90/03/23:14
  26. //  ZONE   +10.5  LHowe   +10.5  LHoweS  +11    89/10/28:16  90/03/03:16
  27. //  ZONE   +10      GMT+10  +10
  28. //  ZONE   +10A   Mos+7   +10     MosS+7  +11    90/03/25:2   90/09/30:2
  29. //  ZONE   +10B   NSW      +10     NSW-S     +11    89/10/28:16  90/03/03:16
  30. //  ZONE   +10C   Vict.   +10     VictS     +11    89/10/28:16  90/03/17:16
  31. //  ZONE   +9.5   AusNT   +9.5
  32. //  ZONE   +9.5B  SAus      +9.5     SAusS     +10.5    89/10/29:16  90/03/17:16
  33. //  ZONE   +9      GMT+9   +9
  34. //  ZONE   +9A      Mos+6   +9     MosS+6  +10    90/03/25:2   90/09/30:2
  35. //  ZONE   +9B      JST      +9
  36. //  REM  Duplicate entry for Japan
  37. //  ZONE   +8      GMT+8   +8
  38. //  ZONE   +8A      Mos+5   +8     MosS+5  +9    90/03/25:2   90/09/30:2
  39. //  ZONE   +8C      China   +8     ChinaS  +9    90/04/15:10  90/09/16:10
  40. //  ZONE   +7      GMT+7   +7
  41. //  ZONE   +7A      Mos+4   +7     MosS+4  +8    90/03/25:2   90/09/30:2
  42. //  ZONE   +6.5   GMT+6.5 +6.5
  43. //  ZONE   +6      GMT+6   +6
  44. //  ZONE   +6A      Mos+3   +6     MosS+3  +7    90/03/25:2   90/09/30:2
  45. //  ZONE   +5.75  Nepal   +5.75
  46. //  ZONE   +5.5   India   +5.5
  47. //  ZONE   +5      GMT+5   +5
  48. //  ZONE   +5A      Mos+2   +5     MosS+2  +6    90/03/25:2   90/09/30:2
  49. //  ZONE   +4.5   Afghn   +4.5
  50. //  ZONE   +4      GMT+4   +4
  51. //  ZONE   +4A      Mos+1   +4     MosS+1  +5    90/03/25:2   90/09/30:2
  52. //  ZONE   +3.5   Iran      +3.5
  53. //  ZONE   +3      GMT+3   +3
  54. //  ZONE   +3A      Mos.      +3     MosS     +4    90/03/25:2   90/09/30:2
  55. //  ZONE   +3B      Iraq      +3     IraqS     +4    90/04/01:1   90/10/01:1
  56. //  ZONE   +2      GMT+2   +2
  57. //  ZONE   +2A      EastEu  +2     EastEuS +3    90/03/25:2   90/09/30:2
  58. //  ZONE   +2B      Isr.      +2     IsrS     +3    90/04/22:1   90/09/02:1
  59. //  ZONE   +2C      Egypt   +2     EgyptS  +3    90/05/01:1   90/10/01:1
  60. //  ZONE   +2D      Jord.   +2     JordS     +3    90/04/06:1   90/10/05:1
  61. //  ZONE   +2E      Leb.      +2     LebS     +3    90/05/01:1   90/10/16:1
  62. //  ZONE   +2F      Syria   +2     SyriaS  +3    90/03/15:1   90/11/01:1
  63. //  ZONE   +1      GMT+1   +1
  64. //  ZONE   +1A      CentEu  +1     CentEuS +2    90/03/25:2   90/09/30:2
  65. //  ZONE   +1B      Libya   +1     LibyaS  +2    90/04/01:2   90/10/01:2
  66. //  ZONE   GMT      GMT       0
  67. //  ZONE   Z      Z       0
  68. //  ZONE   +0A      WestEu   0     WestEuS +1    90/03/25:2   90/09/30:2
  69. //  ZONE   UKT      GMT       0     BST     +1    90/03/25:1   90/10/28:1
  70. //  ZONE   -1A      GMT-1   -1     GMT      0    90/03/25:2   90/09/30:2
  71. //  ZONE   -2      GMT-2   -2
  72. //  REM  This zone currently has no entries
  73. //  ZONE   -2A      FdNor   -2     FdNor-S -1    89/10/15:6   90/02/11:6
  74. //  ZONE   -3      GMT-3   -3
  75. //  ZONE   -3A      GMT-3   -3     GMT-2     -2    90/03/25:2   90/09/30:2
  76. //  ZONE   -3B      Rio      -3     Rio-S     -2    89/10/15:6   90/02/11:6
  77. //  ZONE   -3C      Uru      -3     Uru-S     -2    89/10/29:6   90/03/04:6
  78. //  ZONE   -3D      Arg      -3     Arg-S     -2    89/10/15:6   90:03/04:6
  79. //  ZONE   -3E      SP/Mi   -3     SP/Mi-S -2    90/04/01:6   90/10/28:6
  80. //  ZONE   NFD      Nfd      -3.5     Nfd DT  -2.5    90/04/01:6   90/10/28:6
  81. //  ZONE   -4      GMT-4   -4
  82. //  ZONE   AT      AST      -4     ADT     -3    90/04/01:6   90/10/28:6
  83. //  ZONE   -4B      Falk      -4     FalkS     -3    89/09/10:7   90/04/22:7
  84. //  ZONE   -4C      Chile   -4     ChilS     -3    89/10/15:7   90/03/11:7
  85. //  ZONE   -4D      Para.   -4     ParaS     -3    89/10/22:7   90/04/01:7
  86. //  ZONE   -4E      Berm.   -4     BermS     -3    90/04/01:6   90/10/28:6
  87. //  ZONE   -4F      BrazW   -4     BrazW-S -3    89/10/15:6   90/02/11:6
  88. //  ZONE   -5      GMT-5   -5
  89. //  ZONE   EST      EST      -5
  90. //  REM  Some entries in this zone have been transferred to ZONE "-5"
  91. //  ZONE   ET      EST      -5     EDT     -4    90/04/01:7   90/10/28:7
  92. //  ZONE   -5B      Cuba      -5     CubaS     -4    90/03/18:7   90/10/07:7
  93. //  ZONE   -5C      Peru      -5     PeruS     -4    90/01/01:7   90/04/10:7
  94. //  ZONE   -5E      Carib.  -5     CaribS  -4    90/04/01:7   90/10/28:7
  95. //  REM  A few Caribbean countries that observe DST on U.S. dates
  96. //  ZONE   -6      GMT-6   -6
  97. //  ZONE   CST      CST      -6
  98. //  REM  Some entries in this zone have been transferred to ZONE "-6"
  99. //  ZONE   CT      CST      -6     CDT     -5    90/04/01:8   90/10/20:8
  100. //  ZONE   -6C      Eas.I.  -6     Eas.I.S -5    89/10/15:7   90/03/11:7
  101. //  ZONE   -7      GMT-7   -7
  102. //  ZONE   MST      MST      -7
  103. //  ZONE   MT      MST      -7     MDT     -6    90/04/01:9   90/10/28:9
  104. //  ZONE   -8      GMT-8   -8
  105. //  ZONE   PT      PST      -8     PDT     -7    90/04/01:10  90/10/28:10
  106. //  ZONE   -9      GMT-9   -9
  107. //  ZONE   AKT      AkST      -9     AkDT     -8    90/04/01:11  90/10/28:11
  108. //  ZONE   -9.5   Marq.I. -9.5
  109. //  ZONE   -10      GMT-10  -10
  110. //  ZONE   -10B   CookI   -10     CookIS  -9.5    89/10/29:12  90/03/04:11
  111. //  ZONE   HST      HST      -10
  112. //  ZONE   ALUT   AluST   -10     AluDT     -9    90/04/01:12  90/10/28:12
  113. //  ZONE   -11      GMT-11  -11
  114. //  ZONE   -12      GMT-12  -12
  115.  
  116. //      Tokyo       9 hours     (Do not precede positive numbers with
  117. //      Hong Kong      8 hours      a plus sign during configuration.)
  118. //      Beijing      8 hours
  119. //      Jakarta      8 hours
  120. //      Bombay      5.5 hours
  121. //      Karachi      5 hours
  122. //      Moscow      3 hours
  123. //      Nairobi      3 hours
  124. //      Riyadh      3 hours
  125. //      Cairo       2 hours
  126. //      Johannesburg      2 hours
  127. //      Rome          1 hours
  128. //      Paris       1 hours
  129. //--->      GREENWICH      0 hours    <---   (0 degrees longitude)
  130. //      Dakar       0 hours
  131. //      Reykjavic      0 hours
  132. //      Caracas     -4 hours    (Use the minus sign during configuration.)
  133. //      New York     -5 hours
  134. //      Chicago     -6 hours
  135. //      Mexico City     -6 hours
  136. //      Denver     -7 hours
  137. //      San Francisco  -8 hours
  138. //      Anchorage     -9 hours
  139. //      Honolulu     -10 hours
  140.  
  141. //******** SET TIMEZONE *******************************************************
  142.  
  143.     //Pacific Daylight time is - 7 hours
  144.     //Pacific Standard time is - 8 hours
  145.  
  146.     timezone = -7;
  147.  
  148. //*****************************************************************************
  149.  
  150.     // Initialize variables
  151.     startdtmo="04-";   // starting month of daylight saving time
  152.     startdtdy="01-";   // starting day of daylight saving time
  153.     stopdtmo="10-";    // ending month of daylight saving time
  154.     stopdtdy="28-";    // ending day of daylight saving time
  155.  
  156.     error=1;        //Indicates that time info is yet to be decoded properly
  157.     err_test=-1;    //Used to detect if time info is properly recieved
  158.     hi_hour=-1;     //Receives hi byte of hour time info
  159.     lo_hour=-1;     //Receives lo byte of hour time info
  160.     hi_min=-1;        //Recieves hi byte of minute time info
  161.     lo_min=-1;        //Receives lo byte of minute time info
  162.     hi_sec=-1;        //Receives hi byte of second time info
  163.     lo_sec=-1;        //Recieves lo byte of second time info
  164.     julian1=-1;
  165.     julian2=-1;
  166.     julian3=-1;
  167.     julian4=-1;
  168.     julian5=-1;
  169.     _alarm_on = 0;
  170.     _sound_on = 0;
  171.  
  172.     //Show opening TIMESET display
  173.     clear_scr();
  174.     prints("");
  175.     prints("");
  176.     prints("Welcome to Timeset!!!");
  177.     prints("Now dialing The Naval Observertory for the time...");
  178.  
  179.     //Dial for the time
  180.     set_cparams(1200,0,8,1);
  181.     if(!dial("m1-202-653-0351",10))
  182.     {
  183.     prints("Can not contact the Naval Observatory! Aborting.");
  184.     _alarm_on = 0;
  185.     _sound_on = 0;
  186.     tone(300,1);
  187.     return;        //After 10 tries can't reach the time.  Abort.
  188.     }
  189.  
  190.     // Decode the modified Julian time info received
  191.     while(error)
  192.     {
  193.  
  194.     if(!waitfor("UTC",10))
  195.       {
  196.         prints("Timeout error, aborting!");
  197.         hangup();
  198.         _alarm_on = 0;
  199.         _sound_on = 0;
  200.         return;    //Time info is not flowing right.  Abort.
  201.       }
  202.  
  203.     if(!waitfor("*",3))
  204.       {
  205.         prints("Timeout error, aborting!");
  206.         hangup();
  207.         _alarm_on = 0;
  208.         _sound_on = 0;
  209.         return;    //Time info is not flowing right.  Abort.
  210.       }
  211.     flushbuf();
  212.  
  213.     count=2;       //Amount of bytes to wait until date data should start
  214.     while(count)
  215.     {
  216.         while(cgetc()==-1)
  217.         {
  218.         }
  219.         count=count-1;
  220.     }
  221.     while(julian1==-1)
  222.     {
  223.         julian1=cgetc();
  224.     }
  225.     while(julian2==-1)
  226.     {
  227.         julian2=cgetc();
  228.     }
  229.     while(julian3==-1)
  230.     {
  231.         julian3=cgetc();
  232.     }
  233.     while(julian4==-1)
  234.     {
  235.         julian4=cgetc();
  236.     }
  237.     while(julian5==-1)
  238.     {
  239.         julian5=cgetc();
  240.     }
  241.  
  242.     count=5;       //Amount of bytes to wait until time data should start
  243.     while(count)
  244.     {
  245.         while(cgetc()==-1)
  246.         {
  247.         }
  248.         count=count-1;
  249.     }
  250.  
  251.     //Receive the time data
  252.     while(hi_hour==-1)
  253.     {
  254.         hi_hour=cgetc();
  255.     }
  256.     while(lo_hour==-1)
  257.     {
  258.         lo_hour=cgetc();
  259.     }
  260.     while(hi_min==-1)
  261.     {
  262.         hi_min=cgetc();
  263.     }
  264.     while(lo_min==-1)
  265.     {
  266.         lo_min=cgetc();
  267.     }
  268.     while(hi_sec==-1)
  269.     {
  270.         hi_sec=cgetc();
  271.     }
  272.     while(lo_sec==-1)
  273.     {
  274.         lo_sec=cgetc();
  275.     }
  276.     if(waitfor("UTC",2))
  277.     {
  278.      error = 0;
  279.     }
  280.     }
  281.  
  282.     //Hangup the modem and clear extra received data
  283.     hangup();
  284.     flushbuf();
  285.  
  286.     //Start building the DOS set time command
  287.     strcat(utc_hour,hi_hour);
  288.     strcat(utc_hour,lo_hour);
  289.     local_hr=stoi(utc_hour);
  290.  
  291.     // ****************** Adjust UTC time to local time here *****************
  292.  
  293.     local_hr=local_hr + timezone;
  294.  
  295.     if(local_hr<0)
  296.     {
  297.     local_hr=local_hr+24;
  298.     }
  299.     itos(local_hr,slocal_hr);
  300.     strcat(set_dos_time,slocal_hr);
  301.     strcat(set_dos_time,":");
  302.     strcat(set_dos_time,hi_min);
  303.     strcat(set_dos_time,lo_min);
  304.     strcat(set_dos_time,":");
  305.     strcat(set_dos_time,hi_sec);
  306.     strcat(set_dos_time,lo_sec);
  307.  
  308.     // ***********************************************************************
  309.  
  310. //       ** julian to calender date algorythiom  **
  311.  
  312. //  The algorythiom was obtained directly from the Naval Observertory
  313. //  and should be valid for the next 140 years.
  314. //  if you use it elsewhere be careful of the integer roundoff,
  315. //  the precedence's are critical therefore the () are inserted
  316. //  to clarify them and prevent mistranslation by the reader.
  317.  
  318.     strcat(juldatestr,"24");  // Add epoch to modified julian date
  319.     strcat(juldatestr,julian1);
  320.     strcat(juldatestr,julian2);
  321.     strcat(juldatestr,julian3);
  322.     strcat(juldatestr,julian4);
  323.     strcat(juldatestr,julian5);
  324.  
  325.  
  326.     integerdate = stoi(juldatestr);
  327.     y1 = integerdate + 68569;
  328.     y2 = (4 * y1) / 146097;
  329.     y3 = y1 - (((146097 * y2) + 3) / 4);
  330.     year = (4000 * (y3 + 1)) / 1461001;
  331.     y4 = (y3 - ((1461 * year) / 4)) + 31;
  332.     month = (80 * y4) / 2447;
  333.     day = y4 - ((2447 * month) / 80);
  334.     day = day + 1;
  335.     if(local_hr >= 12)
  336.        day = day - 1;      //Julian day begins at noon so this corrects
  337.     y5 = month / 11;   //apparent one day early in decode.
  338.     month = month + 2 - (12 * y5);
  339.     year = 100 * (y2 - 49) + year + y5;
  340.  
  341.  
  342.     itos(integerdate, geordatestr );
  343.     itos(month, monthstr );
  344.     itos(day, daystr );
  345.     itos(year, yearstr );
  346.  
  347.     strcat(set_dos_date,monthstr);
  348.     strcat(set_dos_date,"-");
  349.     strcat(set_dos_date,daystr);
  350.     strcat(set_dos_date,"-");
  351.     strcat(set_dos_date,yearstr);
  352.  
  353.     // Actualy set the internal clock here!
  354.     //Set DOS time
  355.     dos(set_dos_time,0);
  356.     //Set DOS date
  357.     dos(set_dos_date,0);
  358.  
  359.     clear_scr();
  360.     prints("");
  361.     prints("");
  362.     prints("");
  363.     prints("");
  364.     prints("");
  365.     prints("");
  366.     gotoxy(28,gety());
  367.     prints("SUCCESSFULLY RECEIVED TIME");
  368.  
  369.     //Display current time continuosly
  370.     _scr_chk_key=0;     //Disable keyboard scan so inkey will work properly
  371.     cursor_onoff(0);     //Disable the cursor because it is annoying
  372.     clear_scr();
  373.     prints("");
  374.     prints("");
  375.     prints("");
  376.     printsc("julian date = ");
  377.     prints(juldatestr);
  378.     prints("");
  379.     prints("");
  380.     printsc("month = ");
  381.     prints(monthstr);
  382.     printsc("day = ");
  383.     prints(daystr);
  384.     printsc("year = ");
  385.     prints(yearstr);
  386.     prints("");
  387.     prints("");
  388.     prints("");
  389.     prints("Press esc to exit");
  390.     prints("");
  391.     printsc("The time received from the Naval Observatory is         adjusted to local time.");
  392.  
  393.     while(1)
  394.     {
  395.     gotoxy(48,gety());
  396.     t=curtime();
  397.     if(thour(t)<10)
  398.     {
  399.      printsc("0");
  400.     }
  401.     printn(thour(t));
  402.     if(tmin(t)<10)
  403.     {
  404.      printsc("0");
  405.     }
  406.     printn(tmin(t));
  407.     printsc(".");
  408.     if(tsec(t)<10)
  409.     {
  410.      printsc("0");
  411.     }
  412.     printn(tsec(t));
  413.     if(inkey()==27)
  414.     {
  415.         break;    //Exit if the esc key is pressed
  416.     }
  417.     }
  418.  
  419.     clear_scr();
  420.     prints("Thank you for using TIMESET!");
  421.     exittelix(0, 1);
  422. }
  423.